/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.fsiebert.polytech.db.mediatheque.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Florent
 */
@Entity
@Table(name = "CommandeDuJour")
@NamedQueries({
    @NamedQuery(name = "CommandeDuJour.findAll", query = "SELECT c FROM CommandeDuJour c"),
    @NamedQuery(name = "CommandeDuJour.findByDate", query = "SELECT c FROM CommandeDuJour c WHERE c.date = :date"),
    @NamedQuery(name = "CommandeDuJour.findByIdCommandeDuJour", query = "SELECT c FROM CommandeDuJour c WHERE c.idCommandeDuJour = :idCommandeDuJour")})
public class CommandeDuJour implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Date", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date date;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idCommandeDuJour", nullable = false)
    private Integer idCommandeDuJour;
    @JoinTable(name = "CommandeDuJourItem", joinColumns = {
        @JoinColumn(name = "idCommandeDuJour", referencedColumnName = "idCommandeDuJour", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "ItemRef", referencedColumnName = "ItemRef", nullable = false)})
    @ManyToMany
    private List<Item> itemList;
    @JoinColumn(name = "NoCarte", referencedColumnName = "NoCarte", nullable = false)
    @ManyToOne(optional = false)
    private Adherent noCarte;

    public CommandeDuJour() {
    }

    public CommandeDuJour(Integer idCommandeDuJour) {
        this.idCommandeDuJour = idCommandeDuJour;
    }

    public CommandeDuJour(Integer idCommandeDuJour, Date date) {
        this.idCommandeDuJour = idCommandeDuJour;
        this.date = date;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Integer getIdCommandeDuJour() {
        return idCommandeDuJour;
    }

    public void setIdCommandeDuJour(Integer idCommandeDuJour) {
        this.idCommandeDuJour = idCommandeDuJour;
    }

    public List<Item> getItemList() {
        return itemList;
    }

    public void setItemList(List<Item> itemList) {
        this.itemList = itemList;
    }

    public Adherent getNoCarte() {
        return noCarte;
    }

    public void setNoCarte(Adherent noCarte) {
        this.noCarte = noCarte;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCommandeDuJour != null ? idCommandeDuJour.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CommandeDuJour)) {
            return false;
        }
        CommandeDuJour other = (CommandeDuJour) object;
        if ((this.idCommandeDuJour == null && other.idCommandeDuJour != null) || (this.idCommandeDuJour != null && !this.idCommandeDuJour.equals(other.idCommandeDuJour))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "eu.fsiebert.polytech.db.mediatheque.entity.CommandeDuJour[ idCommandeDuJour=" + idCommandeDuJour + " ]";
    }
    
}
